const app = new Vue({
    el: "#app",
    data: {
        placeholder: "请输入小区名称",
        districtName: "请选择", //区域
        areaName: "请选择", //小区名称
        area: {
            code: "",
            name: "",
        },
        building: {
            code: "",
            name: "",
        },
        changeName: {
            districtName: "", //区域
            areaName: "", //小区名称
        },
        districtVisible: false,
        areaVisible: false,
        searchValue: "",
        district: [
            {
                flex: 1,
                values: [],
                className: "slot1",
            },
        ],
        areaList: [],
        buildList: [],
        buildList: [],
        houseList: [],
        formData: {
            Budget: "1_50",
            District: "不限",
            HouseLayout: ["1", "2"],
            OpenId: "o5GGA4gB5o5tm3Cc6z-th6IUxIWY",
            Preference: "新房",
            SpecialRequirement: [
                "优质学区",
                "离地铁近",
                "生活便利",
                "南北通透",
                "车位充足",
                "高楼层",
                "中间楼层",
                "绿化率高",
                "优质物业",
            ],
            WhichTimeHomebuyer: "二套",
            budget: "1_50",
            district: "不限",
            houseLayout: "1,2",
            openId: "o5GGA4gB5o5tm3Cc6z-th6IUxIWY",
            preference: "新房",
            specialRequirement:
                "优质学区,离地铁近,生活便利,南北通透,车位充足,高楼层,中间楼层,绿化率高,优质物业",
            whichTimeHomeBuyer: "二套",
        },
        phNumber: "15022334455",
        minValue: 1, // slider 左边滑块初始位置
        maxValue: 50, // slider 右边滑块初始位置
        minValueFocus: false,
        idxQ: "0",
        idxT: "0",
        idxM: ["1"],
        houseQty: [
            {
                name: "首套",
                id: "0",
            },
            {
                name: "二套",
                id: "1",
            },
        ],
        houseType: [
            {
                name: "二手房",
                id: "0",
            },
            {
                name: "新房",
                id: "1",
            },
            {
                name: "不限",
                id: "2",
            },
        ],
        houseModel: [
            {
                name: "1居",
                id: "0",
                value: "1",
                isSelected: true,
            },
            {
                name: "2居",
                id: "1",
                value: "2",
                isSelected: false,
            },
            {
                name: "3居",
                id: "2",
                value: "3",
                isSelected: false,
            },
            {
                name: "4居",
                id: "3",
                value: "4",
                isSelected: false,
            },
            {
                name: "5居",
                id: "4",
                value: "5",
                isSelected: false,
            },
            {
                name: "5+居",
                id: "5",
                value: "5+",
                isSelected: false,
            },
        ],
        requireType: [
            {
                id: "1",
                name: "优质学区",
                isSelected: true,
            },
            {
                id: "2",
                name: "离地铁近",
                isSelected: false,
            },
            {
                id: "3",
                name: "生活便利",
                isSelected: false,
            },
            {
                id: "4",
                name: "南北通透",
                isSelected: false,
            },
            {
                id: "5",
                name: "车位充足",
                isSelected: false,
            },
            {
                id: "6",
                name: "高楼层",
                isSelected: false,
            },
            {
                id: "7",
                name: "中间楼层",
                isSelected: false,
            },
            {
                id: "8",
                name: "绿化率高",
                isSelected: false,
            },
            {
                id: "9",
                name: "带电梯",
                isSelected: false,
            },
            {
                id: "10",
                name: "优质物业",
                isSelected: false,
            },
            {
                id: "11",
                name: "不要顶层",
                isSelected: false,
            },
            {
                id: "12",
                name: "不要底层",
                isSelected: false,
            },
        ],
    },
    mounted() {
        this.getBasicData();
    },
    methods: {
        confirmUnit(item) {
            // 获取房间号
            this.houseList.splice(0, this.houseList.length);
            this.building.name = item.buildingName;
            this.building.code = item.buildingCode;
            this.searchValue = "";
            axios
                .post(`${rht_server}KeHouse/SearchHouseToSell`, {
                    buildingId: this.building.code,
                    pageSize: 800,
                })
                .then((res) => {
                    if (res.data.code == 200) {
                        this.houseList = res.data.data;
                    } else {
                        console.log(err);
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        openAddress() {
            // 选择具体地址
            if (this.areaName == "请选择") {
                this.openMessage("请先选择小区名称");
                return;
            }
            this.placeholder = "请输入楼栋号";
            this.areaList.splice(0, this.areaList.length);
            this.areaVisible = true;
            axios
                .post(`${rht_server}KeBuilding/SearchAddressToSell`, {
                    districtId: this.area.code,
                    pageSize: 600,
                })
                .then((res) => {
                    if (res.data.code == 200) {
                        this.buildList = res.data.data;
                    } else {
                        console.log(err);
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        confirmBuilding(item) {
            this.buildList.splice(0, this.buildList.length);
            this.building.name = item.buildingName;
            this.building.code = item.buildingCode;
            this.searchValue = "";
            axios
                .post(`${rht_server}KeUnit/SearchUnitToSell`, {
                    buildingId: this.building.code,
                    pageSize: 800,
                })
                .then((res) => {
                    if (res.data.code == 200) {
                        this.houseList = res.data.data;
                    } else {
                        console.log(err);
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        confirmArea(item) {
            this.areaVisible = false;
            this.areaName = this.area.name = item.name;
            this.area.code = item.code;
            this.searchValue = "";
        },
        searchArea(e) {
            console.log(e);
            axios
                .post(`${rht_server}keEstate/SearchDistrictToSell`, {
                    name: e,
                })
                .then((res) => {
                    if (res.data.code == 200) {
                        this.areaList = res.data.data;
                    } else {
                        console.log(err);
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        openArea() {
            // 选择小区
            this.placeholder = "请输入小区名称";
            this.areaList.splice(0, this.areaList.length);
            this.areaVisible = true;
        },
        onConfirm() {
            this.districtVisible = false;
            this.districtName = this.changeName;
        },
        onChange(picker, values) {
            this.changeName = values[0];
        },
        async getBasicData() {
            let resData = await axios.get(
                `${rht_server}BasicDataApi/GetBasicData`
            );
            resData.data.data.districtList.forEach((ele) => {
                this.district[0].values.push(ele.name);
            });
            this.district[0].values.unshift("不限");
        },
        selectHandle(type, item) {
            if (type == "houseQty") {
                this.idxQ = item.id;
            } else if (type == "houseType") {
                this.idxT = item.id;
            } else if (type == "houseModel") {
                item.isSelected = !item.isSelected;
            } else if (type == "requireType") {
                item.isSelected = !item.isSelected;
            }
        },
        submit() {},
        openMessage(message) {
            this.$toast({
                message: message,
                duration: 3000,
            });
        },
    },
});
